package com.yhx.service;

import com.yhx.pojo.User;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author uknow
 * @description  服务降级
 * @date 2020/6/14 10:07
 */
@Component
public class UserClientServiceFallbackFactory implements FallbackFactory<UserClientService> {

    public UserClientService create(Throwable throwable) {
        return new UserClientService() {
            public User queryUser(Integer id) {
                return new User().setId(id)
                        .setName("id="+id+"没有对应的信息，客户端提供了降级信息，这个服务现在已经被关闭");
            }

            public List<User> queryUsers() {
                return null;
            }

            public List<User> queryUserByName(String name) {
                List<User> users = new ArrayList<User>();
                User user = new User().setId(0).setName("没有对应的信息，服务降级");
                users.add(user);
                return users;
            }
        };
    }
}
